<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>忘记密码 - layuiAdmin</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="../../layuiadmin/style/login.css" media="all">
</head>

<body>
<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2>大众纺织网</h2>
            <p>纺织市场便民服务</p>
        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-cellphone"
                       for="LAY-user-login-cellphone"></label>
                <input type="text" name="adminname" id="LAY-user-login-adminname" lay-verify="required"
                       placeholder="用户名" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-cellphone"
                       for="LAY-user-login-cellphone"></label>
                <input type="text" name="cellphone" id="LAY-user-login-cellphone" lay-verify="phone" placeholder="手机"
                       class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                       for="LAY-user-login-password"></label>
                <input type="password" name="password" id="LAY-user-login-password" lay-verify="pass" placeholder="密码"
                       class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                       for="LAY-user-login-repass"></label>
                <input type="password" name="repass" id="LAY-user-login-repass" lay-verify="required" placeholder="确认密码"
                       class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-username"
                       for="LAY-user-login-nickname"></label>
                <input type="text" name="nickname" id="LAY-user-login-nickname" lay-verify="nickname" placeholder="昵称"
                       class="layui-input">
            </div>
            <div class="layui-form-item">
                <input type="checkbox" name="agreement" lay-skin="primary" title="同意用户协议" checked>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-reg-submit">注 册</button>
            </div>
            <div class="layui-trans layui-form-item layadmin-user-login-other">


                <a href="/views/login.html" class="layadmin-user-jump-change layadmin-link layui-hide-xs">用已有帐号登入</a>
                <a href="/views/login.html"
                   class="layadmin-user-jump-change layadmin-link layui-hide-sm layui-show-xs-inline-block">登入</a>
            </div>
        </div>
    </div>

    <div class="layui-trans layadmin-user-login-footer">

        <p>© 2018 大众纺织网</p>

    </div>

</div>

<script src="../../layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'user', 'layer'], function () {
        var $ = layui.$
            , setter = layui.setter
            , admin = layui.admin
            , form = layui.form
            , layer = layui.layer
            , router = layui.router();

        form.render();

        //离开输入框进行用户名验证是否存在
        $("#LAY-user-login-adminname").blur(function () {
            $.ajax({
                url: '/user/getadmincount' //实际使用请改成服务端真实接口
                , data: JSON.stringify({"adminname": $("#LAY-user-login-adminname").val()})
                , type: "post"
                , datatype: "text"
                , contentType: "application/json;charset=UTF-8"
                , success: function (res) {
                    if (res == 'failure') {
                        layer.msg('用户名已存在', {
                            icon: 5,
                            time: 2000,
                            offset: '15px'
                        });
                        $("#LAY-user-login-adminname").css({"border": "1px solid red"});
                    }
                }
            });
        });
        //清除样式
        $("#LAY-user-login-adminname").click(function () {
            $("#LAY-user-login-adminname").css({"border": ""})
        });

        // form.verify({
        //     adminone:function(value,item){
        //       $.ajax({
        //         url: '/user/getadmincount' //实际使用请改成服务端真实接口
        //         , data: JSON.stringify({"adminname": value})
        //         , type: "post"
        //         , datatype: "text"
        //         , contentType: "application/json;charset=UTF-8"
        //         , success: function (res) {
        //           if (res == 'failure') {
        //             layer.msg('用户名已存在', {
        //               icon: 5,
        //               time: 2000,
        //               offset: '15px'
        //             });
        //           }
        //         }
        //       })
        //     }
        // });

        //提交
        form.on('submit(LAY-user-reg-submit)', function (obj) {
            var field = obj.field;

            //确认密码
            if (field.password !== field.repass) {
                return layer.msg('两次密码输入不一致');
            }

            //是否同意用户协议
            if (!field.agreement) {
                return layer.msg('你必须同意用户协议才能注册');
            }

            $.ajax({
                url: '/user/register' //实际使用请改成服务端真实接口
                , data: JSON.stringify(field)
                , type: "post"
                , dataType: "text"
                , contentType: "application/json;charset=UTF-8"
                , success: function (res) {
                    if (res == 'success') {
                        //登入成功的提示与跳转
                        layer.msg('注册成功', {
                            offset: '15px'
                            , icon: 1
                            , time: 2000
                        }, function () {

                            location.href = "/views/login.html"; //后台主页
                        });
                    } else if (res == 'failure') {
                        layer.msg('注册失败', {
                            offset: '15px'
                            , icon: 5
                            , time: 2000
                        });
                    } else if (res == 'null-error') {
                        layer.msg('注册失败，两次密码不一致', {
                            offset: '15px'
                            , icon: 5
                            , time: 2000
                        });
                    }

                }
            });
        });
    });

</script>
</body>
</html>